//
//  XMWeiboUser.m
//  XMWeibo
//
//  Created by chi on 14-8-23.
//  Copyright (c) 2014年 xiaoming. All rights reserved.
//

#import "XMWeiboUser.h"
#import "MJExtension.h"

@implementation XMWeiboUser


/**
 *  从文件初始化类
 */
- (id)initWithCoder:(NSCoder *)aDecoder
{
    if (self = [super init]) {
        self.idstr = [aDecoder decodeObjectForKey:@"idstr"];
        self.screen_name = [aDecoder decodeObjectForKey:@"screen_name"];
        self.location = [aDecoder decodeObjectForKey:@"location"];
        self.name = [aDecoder decodeObjectForKey:@"name"];
        self.userDescription = [aDecoder decodeObjectForKey:@"userDescription"];
        self.profile_image_url = [aDecoder decodeObjectForKey:@"profile_image_url"];
        self.mbrank = [[aDecoder decodeObjectForKey:@"mbrank"] intValue];
        self.mbtype = [[aDecoder decodeObjectForKey:@"mbtype"] intValue];
        
        self.statuses_count = [[aDecoder decodeObjectForKey:@"statuses_count"] intValue];
        self.friends_count = [[aDecoder decodeObjectForKey:@"friends_count"] intValue];
        self.followers_count = [[aDecoder decodeObjectForKey:@"followers_count"] intValue];

    }
    
    return self;
}

/**
 *  归档
 */
- (void)encodeWithCoder:(NSCoder *)aCoder
{
    [aCoder encodeObject:self.idstr forKey:@"idstr"];
    [aCoder encodeObject:self.screen_name forKey:@"screen_name"];
    [aCoder encodeObject:self.location forKey:@"location"];
    [aCoder encodeObject:self.name forKey:@"name"];
    [aCoder encodeObject:self.userDescription forKey:@"userDescription"];
    [aCoder encodeObject:self.profile_image_url forKey:@"profile_image_url"];
    [aCoder encodeObject:@(self.mbrank) forKey:@"mbrank"];
    [aCoder encodeObject:@(self.mbtype) forKey:@"mbtype"];
    
    [aCoder encodeObject:@(self.statuses_count) forKey:@"statuses_count"];
    [aCoder encodeObject:@(self.friends_count) forKey:@"friends_count"];
    [aCoder encodeObject:@(self.followers_count) forKey:@"followers_count"];
    
}

/*** 解档 */
+ (instancetype)loadWeiboUserFromFile
{
    
    NSString *path = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES)[0];
    path= [path stringByAppendingPathComponent:@"weibouser.dat"];
    
    
    return [NSKeyedUnarchiver unarchiveObjectWithFile:path];
}

/*** 归档 */
- (void)saveWeiboUserToFile
{
    NSString *path = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES)[0];
    path= [path stringByAppendingPathComponent:@"weibouser.dat"];
    
    [NSKeyedArchiver archiveRootObject:self toFile:path];
}

@end
